package org.zero.orika.mapper;

import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.converter.ConverterFactory;
import ma.glasnost.orika.impl.ConfigurableMapper;
import org.zero.model.dto.AccountDTO;
import org.zero.model.po.AccountPO;
import org.zero.orika.converter.StatusConverter;

/**
 * @author Zero (cnzeropro@qq.com)
 * @date 2021/9/1 15:37
 */
public class AccountMapper extends ConfigurableMapper {
    @Override
    protected void configure(MapperFactory factory) {
        ConverterFactory converterFactory = factory.getConverterFactory();
        // 状态转换器（双向：Byte-StatusEnum）
        converterFactory.registerConverter("statusConverter", new StatusConverter());

        factory.classMap(AccountPO.class, AccountDTO.class)
                // 添加自定义转换器
                .fieldMap("status")
                .converter("statusConverter")
                .add()
                // 其它属性使用默认映射器
                .byDefault()
                // 注册
                .register();
    }
}
